package com.mowuju.data.jike.rpc;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.ipc.RPC;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Objects;

/**
 * @author liumo yangqiuhua@xincheng818.com
 * @project: mapreduce
 * @description:
 * @date 2021/7/25
 */
public class RpcClient {
    public void init() {
        InetSocketAddress inetSocketAddress = new InetSocketAddress("localhost", 7021);
        try {
            PersonProtocol personProtocol = RPC.getProxy(PersonProtocol.class, 33, inetSocketAddress, new Configuration());

            String result1 = personProtocol.findName(20210123456789L);
            String result2 = personProtocol.findName(929283892);

            if (Objects.nonNull(result1)) {
                System.out.println(result1);
            } else {
                System.out.println("result1 is null.");
            }

            if (Objects.nonNull(result2)) {
                System.out.println(result2);
            } else {
                System.out.println("result2 is null.");
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String ...argv) {
        RpcClient client = new RpcClient();
        client.init();
    }
}
